const format = {
    TreeToFlat(data, childrenKey) {
        // data树状数据源，childrenKey子节点属性名
        let flat = []
        for (let item of data) {
            if (item[childrenKey]) {
                flat.push(...this.TreeToFlat(item[childrenKey]))
            } else {
                flat.push(item)
            }
        }
        return flat
    },
    FlatToTree(data, parentKey) {
        // data树状数据源，parentKey父节点属性名
        let tree = []
        for (let item of data) {
            if (!item[parentKey]) {
                continue
            }
            if (item[parentKey] == [parentKey + "Id"]) {
                item.children = this.FlatToTree(data, item[parentKey + "Id"])
                tree.push(item)
            }
        }
        return tree
    },
}
export default format
